import java.util.Arrays;

public class t740 {
    public static void main(String[] args) {
        int arr [] = {2,2,3,3,3,4};
        Arrays.sort(arr);
        int n = arr.length;
        /*if(n ==1){
            return arr[0];
        }*/
        int num[] = new int[arr[arr.length-1]+1];
        int m = num.length;
        for(int k :arr){
            num[k]++;
        }
        //System.out.println(Arrays.toString(num));
        int dp[] = new int [m+1];
        dp[0] = 0;
        dp[1] = num[1];
        int max = 0;
        for(int i = 2;i<m;i++){
            dp[i] = Math.max(dp[i-2]+i*num[i],dp[i-1]);
            max = Math.max(max,dp[i]);
        }
        //return max;
        System.out.println(max);


    }
}
